package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dao.DepDao;
import com.entity.Dep;
import com.service.IDepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepServiceImpl implements IDepService {

    @Autowired
    private DepDao depDao;

    @Override
    public int addDep(Dep dep) {
        return depDao.insert(dep);
    }

    @Override
    public List findAllDep() {
        return depDao.selectList(null);
    }

    @Override
    public Dep findById(Integer depId) {
        return depDao.selectById(depId);
    }

    @Override
    public IPage pearchDep(int page, int limit, Integer depId, String depName) {
        //封装分页参数
        Page pagePearch=new Page(page,limit);
        //封装查询参数
        QueryWrapper q=new QueryWrapper();
        if (depId!=null){
            q.eq("depId",depId);
        }
        if (depName!=null && depName.length()>0){
            q.eq("depName",depName);
        }
        //查
        IPage result=depDao.selectPage(pagePearch,q);

        return result;
    }
}
